package com.example.core.controller;

import cn.hutool.core.collection.CollectionUtil;
import com.example.core.domain.R;
import com.example.core.domain.TableDataInfo;
import com.github.pagehelper.PageInfo;

import java.util.List;

public class BaseController {

    public R<Void> toResult(int rows){
        return rows>0?R.ok():R.fail();



    }public R<Void> toResult(boolean result){
        return result?R.ok():R.fail();
    }

    public TableDataInfo getDataTable(List<?> list) {
        if (CollectionUtil.isEmpty(list)) {
            return TableDataInfo.empty();
        }
        return TableDataInfo.success(list, new PageInfo(list).getTotal());
    }
    protected R<Void> toAjax(int rows) {
        return rows > 0 ? R.ok() : R.fail();
    }

    /**
     * 响应返回结果
     *
     * @param result 结果
     * @return 操作结果
     */
    protected R<Void> toAjax(boolean result) {
        return result ? R.ok() : R.fail();
    }

}
